package org.lonetree.tc.core.dao;


public abstract class DAOFactory {
	
	private static final String STUB_FACTORY = "org.lonetree.tc.core.dao.StubDAOFactory";
	private static final String DB_FACTORY = "org.lonetree.tc.core.dao.DBDAOFactory";
	
	/**
	 * Choices for DAO implementations.
	 *
	 */
	public enum FactoryImplementation{
		STUB_DAO_FACTORY,
		DB_DAO_FACTORY;
	}
	
	/**
	 * Get a DAO factory.
	 *
	 * @param implementationChoice - the choice of implementation
	 * @return a DAO factory
	 */
	public static DAOFactory getDAOFactory(FactoryImplementation implementationChoice){
		switch(implementationChoice){
			case STUB_DAO_FACTORY:
				return instantiateDAOFactory(STUB_FACTORY);
			default: //DB
				return instantiateDAOFactory(DB_FACTORY);
		}
	}
	
	private static DAOFactory instantiateDAOFactory(String className){
		try{
			return (DAOFactory)Class.forName(className).newInstance();
		}
		catch(Exception e){
			return null;
		}
	}
	
	/**
	 * Get a DAO that can create, retrieve, update, delete and find books.
	 *
	 * @return a DAO for books
	 */
	public abstract BookDAO getBookDAO();
	
	/**
	 * Get a DAO that can create, retrieve, update, delete and find courses.
	 *
	 * @return a DAO for courses
	 */
	public abstract CourseDAO getCourseDAO();
	
	/**
	 * Get a DAO that can create, retrieve, update, delete and find users.
	 *
	 * @return a DAO for users
	 */
	public abstract UserDAO getUserDAO();
}
